home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1995 #5 & #6
/
Amiga Plus CD - 1995 - No. 5 and 6.iso
/
pd
/
netz
/
term
/
extras
/
source
/
gtlayout-source.lha
/
LTP_GlyphSetup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-31
|
3KB
|
177 lines
/* GadTools layout toolkit
**
** Copyright © 1993-1995 by Olaf `Olsen' Barthel
** Freely distributable.
*/
#include "gtlayout_global.h"
VOID __regargs
LTP_GetDefaultFont(struct TTextAttr *TextAttr)
{
struct TextFont *Font = GfxBase -> DefaultFont;
TextAttr -> tta_Name = Font -> tf_Message . mn_Node . ln_Name;
TextAttr -> tta_YSize = Font -> tf_YSize;
TextAttr -> tta_Style = Font -> tf_Style;
TextAttr -> tta_Flags = Font -> tf_Flags & ~FPF_REMOVED;
if(Font -> tf_Style & FSF_TAGGED)
TextAttr -> tta_Tags = ((struct TextFontExtension *)Font -> tf_Extension) -> tfe_Tags;
else
TextAttr -> tta_Tags = NULL;
}
/*****************************************************************************/
struct TextFont * __regargs
LTP_OpenFont(struct TextAttr *TextAttr)
{
struct TextFont *Font;
// Let's see if this one is special
if(TextAttr == (struct TextAttr *)~0)
{
struct TTextAttr LocalTextAttr;
memset(&LocalTextAttr,0,sizeof(LocalTextAttr));
Forbid();
// Borrow the system default font data
LTP_GetDefaultFont(&LocalTextAttr);
// Let's hope the font will open...
Font = OpenFont((struct TextAttr *)&LocalTextAttr);
Permit();
}
else
{
if(!(Font = OpenFont(TextAttr)))
{
if(SysBase -> ThisTask -> tc_Node . ln_Type != NT_TASK)
{
struct Library *DiskfontBase;
if(DiskfontBase = OpenLibrary("diskfont.library",0))
{
Font = OpenDiskFont(TextAttr);
CloseLibrary(DiskfontBase);
}
}
}
}
return(Font);
}
/*****************************************************************************/
BOOLEAN __regargs
LTP_GlyphSetup(struct LayoutHandle *Handle,struct TextAttr *TextAttr)
{
struct TextFont *Font;
if(TextAttr)
{
Handle -> TextAttr = TextAttr;
if(Font = LTP_OpenFont(Handle -> TextAttr))
{
if(Handle -> CloseFont)
CloseFont(Handle -> RPort . Font);
else
Handle -> CloseFont = TRUE;
}
}
else
{
Handle -> TextAttr = Handle -> Screen -> Font;
Font = Handle -> DrawInfo -> dri_Font;
if(Handle -> CloseFont)
{
CloseFont(Handle -> RPort . Font);
Handle -> CloseFont = FALSE;
}
}
if(Font)
{
LONG Count = 0;
LONG Total = 0;
UBYTE Glyph;
UWORD i;
LTP_SetFont(Handle,Font);
// Ok, first cover the standard ASCII character set
for(i = 32 ; i < 127 ; i++,Count++)
{
Glyph = i;
Total += TextLength(&Handle -> RPort,&Glyph,1);
}
// Now for the ISO part...
for(i = 160 ; i < 256 ; i++,Count++)
{
Glyph = i;
Total += TextLength(&Handle -> RPort,&Glyph,1);
}
Handle -> GlyphWidth = Total / Count;
// Now for the numeric characters
for(Total = 0, i = '0' ; i <= '9' ; i++)
{
Glyph = i;
Total += TextLength(&Handle -> RPort,&Glyph,1);
}
// Actually, the numeric character should be
// just as wide as the space character. Let's
// hope for the best.
Count = TextLength(&Handle -> RPort," ",1);
Total /= 10;
if(Total < Count)
Total = Count;
if(Total > Handle -> GlyphWidth)
Handle -> GlyphWidth = Total;
if(Handle -> GlyphWidth <= 8)
Handle -> InterWidth = 4;
else
Handle -> InterWidth = Handle -> GlyphWidth / 2;
if(Handle -> RPort . TxHeight <= 8)
Handle -> InterHeight = 2;
else
Handle -> InterHeight = Handle -> RPort . TxHeight / 4;
return(TRUE);
}
else
return(FALSE);
}